<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/5.13.0/css/all.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"horsenliu.gitee.io","root":"/blog/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","width":240,"display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="0. 常见面试题 JVM 内存模型以及分区，需要详细到每个区放什么 堆里面的分区：Eden，Survival from to，老年代，各自的特点。 GC 的三种收集方法：标记清除，标记整理，复制算法的原理与特点，分别用在什么地方 Minor GC 与 Full GC 分别在什么时候发生  1. GC 算法总体概述一个对象的历程   JVM 在进行GC时，并非每次都对上面三个内存区域一起回收的，大部">
<meta property="og:type" content="article">
<meta property="og:title" content="06_GC 详解">
<meta property="og:url" content="http://horsenliu.gitee.io/blog/posts/5c68b0b8.html">
<meta property="og:site_name" content="霍森的笔记本">
<meta property="og:description" content="0. 常见面试题 JVM 内存模型以及分区，需要详细到每个区放什么 堆里面的分区：Eden，Survival from to，老年代，各自的特点。 GC 的三种收集方法：标记清除，标记整理，复制算法的原理与特点，分别用在什么地方 Minor GC 与 Full GC 分别在什么时候发生  1. GC 算法总体概述一个对象的历程   JVM 在进行GC时，并非每次都对上面三个内存区域一起回收的，大部">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://horsenliu.gitee.io/blog/blog/posts/blog/posts/5c68b0b8/image-20200922082947515.png">
<meta property="og:image" content="http://horsenliu.gitee.io/blog/blog/posts/blog/posts/5c68b0b8/image-20200922083137251.png">
<meta property="og:image" content="http://horsenliu.gitee.io/blog/blog/posts/blog/posts/5c68b0b8/image-20200922085159717.png">
<meta property="og:image" content="http://horsenliu.gitee.io/blog/blog/posts/blog/posts/5c68b0b8/image-20200922090752833.png">
<meta property="og:image" content="http://horsenliu.gitee.io/blog/blog/posts/blog/posts/5c68b0b8/image-20200922091120493.png">
<meta property="article:published_time" content="2020-09-21T14:15:00.000Z">
<meta property="article:modified_time" content="2020-10-12T00:36:33.078Z">
<meta property="article:author" content="Horsen Liu">
<meta property="article:tag" content="JVM">
<meta property="article:tag" content="GC">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://horsenliu.gitee.io/blog/blog/posts/blog/posts/5c68b0b8/image-20200922082947515.png">

<link rel="canonical" href="http://horsenliu.gitee.io/blog/posts/5c68b0b8.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>06_GC 详解 | 霍森的笔记本</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">霍森的笔记本</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">记的不少 会的不多</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">123</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">36</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">220</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/horsenliu" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://horsenliu.gitee.io/blog/posts/5c68b0b8.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.png">
      <meta itemprop="name" content="Horsen Liu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="霍森的笔记本">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          06_GC 详解
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-09-21 22:15:00" itemprop="dateCreated datePublished" datetime="2020-09-21T22:15:00+08:00">2020-09-21</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Java-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">Java 学习笔记</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Java-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/JVM/" itemprop="url" rel="index"><span itemprop="name">JVM</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="0-常见面试题"><a href="#0-常见面试题" class="headerlink" title="0. 常见面试题"></a>0. 常见面试题</h3><ol>
<li>JVM 内存模型以及分区，需要详细到每个区放什么</li>
<li>堆里面的分区：Eden，Survival from to，老年代，各自的特点。</li>
<li>GC 的三种收集方法：标记清除，标记整理，复制算法的原理与特点，分别用在什么地方</li>
<li>Minor GC 与 Full GC 分别在什么时候发生</li>
</ol>
<h3 id="1-GC-算法总体概述"><a href="#1-GC-算法总体概述" class="headerlink" title="1. GC 算法总体概述"></a>1. GC 算法总体概述</h3><p>一个对象的历程</p>
<img src="/blog/blog/posts/blog/posts/5c68b0b8/image-20200922082947515.png" class>

<p><strong>JVM 在进行GC时，并非每次都对上面三个内存区域一起回收的，大部分时候回收的都是指新生代</strong></p>
<p>因此 GC 按照回收的区域又分了两种类型，一种是普通的 GC（minor GC），一种是全局 GC （major GC or Full GC）</p>
<ul>
<li>普通 GC：只针对新生代区域的 GC</li>
<li>全局 GC：针对老年代的 GC，偶尔伴随对新生代的 GC 以及对永久代的 GC</li>
</ul>
<span id="more"></span>

<h3 id="2-GC-四大算法"><a href="#2-GC-四大算法" class="headerlink" title="2. GC 四大算法"></a>2. GC 四大算法</h3><h4 id="2-1-引用计数法"><a href="#2-1-引用计数法" class="headerlink" title="2.1 引用计数法"></a>2.1 引用计数法</h4><img src="/blog/blog/posts/blog/posts/5c68b0b8/image-20200922083137251.png" class>

<p>每个对象有一个引用计数器，当对象被引用一次则计数器加 1，当对象引用失效一次，则计数器减 1，计数器为 0 的对象意味着是垃圾对象，可以被 GC 回收。</p>
<p>目前虚拟机基本都是采用<strong>可达性算法</strong>，从 GC Roots 作为起点开始搜索，那么整个连通图中的对象边都是活对象，对于 GC Roots 无法到达的对象变成了垃圾回收对象，随时可被 GC 回收。</p>
<p>缺点：</p>
<ul>
<li>每次对对象赋值时均要维护引用计数器，且计数器本身也有一定的消耗。</li>
<li>较难处理循环引用</li>
</ul>
<p><strong>JVM 的实现一般不采用这种方式</strong></p>
<h4 id="2-2-复制算法-Copying"><a href="#2-2-复制算法-Copying" class="headerlink" title="2.2 复制算法 Copying"></a>2.2 复制算法 Copying</h4><p><strong>年轻代中使用的 Minor GC，采用的就是复制算法（Copying）</strong></p>
<p>Minor GC 会把 Eden 中的所有活的对象都移到 Survivor 区域中，如果 Survivor 区中放不下，那么剩下的活的对象就被移动到 Old Generation 中，也就是说，<strong>一旦收集后，Eden 就是变成空的了。</strong></p>
<p>当对象在 Eden（包括一个 Survivor 区域，这里假设是 From 区域）出生，在经过一次 Minor GC 后，如果对象还存活，并且能够被另外一块 Survivor 区域所容纳 （To 区域 ，即 To 区域有足够的内存空间来存储 Eden 和 From 区域中存活的对象），则使用复制算法将这些仍然还活着的对象复**制到另外一块 **Survivor 区域（To 区域）中，然后清理所使用过的 Eden 以及 Survivor 区域（Form 区域），并且将这些对象的年龄设置为 1。</p>
<p>以后对象在 Survivor 区，每熬过一次 Minor GC，就将这个对象的年龄 + 1，当这个对象的年龄达到某一个值的时候（默认是15岁，通过<code>XX:MaxTenuringThreshold</code>设定参数）这些对象就会成为老年代。</p>
<p>面试题：如何判断哪个是 To 区呢？一句话：<strong>谁空谁是 To</strong></p>
<hr>
<p>复制算法的思想就是将内存分为两块，每次只用其中一块，当这一块内存用完，就将还活着的对象复制到另外一块上面。</p>
<img src="/blog/blog/posts/blog/posts/5c68b0b8/image-20200922085159717.png" class>

<ul>
<li>优点<ul>
<li>不会产生内存碎片。</li>
</ul>
</li>
<li>缺点<ul>
<li>浪费了一半的内存，这太要命了；</li>
<li>如果对象的存活率很高，我们可以极端一点，假设是100%存活，那么我们需要将所有对象都复制一 遍，并将所有引用地址重置一遍。复制这一工作所花费的时间，在对象存活率达到一定程度时，将会变的不可忽视，所以从以上描述不难看出。复制算法要想使用，最起码对象的存活率要非常低才行，而且最重要的是，我们必须要克服50%的内存浪费。</li>
</ul>
</li>
</ul>
<h4 id="2-3-标记清除法-Mark-Sweep"><a href="#2-3-标记清除法-Mark-Sweep" class="headerlink" title="2.3 标记清除法 Mark-Sweep"></a>2.3 标记清除法 Mark-Sweep</h4><p><strong>老年代一般是由标记清除或者是标记清除与标记整理的混合实现</strong></p>
<p>当堆中的有效内存空间被耗尽的时候，就会停止整个程序（也被称为 stop the world），然后进行两项工作，第一项则是标记，第二项则是清除。</p>
<img src="/blog/blog/posts/blog/posts/5c68b0b8/image-20200922090752833.png" class>

<ul>
<li><p>标记：从引用根节点开始标记所有被引用的对象，标记的过程其实就是遍历所有的 GC Roots ，然后将所有 GC Roots 可达的对象，标记为存活的对象。</p>
</li>
<li><p>清除： 遍历整个堆，把未标记的对象清除。</p>
</li>
</ul>
<p>缺点：</p>
<ol>
<li>效率比较低（递归与全堆对象遍历），而且在进行 GC 的时候，需要停止应用程序，这会导致用户体验非常差劲；</li>
<li>这种方式清理出来的空闲内存是不连续的。这点不难理解，我们的死亡对象都是随机的出现在内存的各个角落，现在把他们清除之后，内存的布局自然乱七八糟，而为了应付 这一点，JVM 就不得不维持一个内存空间的空闲列表，这又是一种开销。而且在分配数组对象的时候，寻找连续的内存空间会不太好找。</li>
</ol>
<h4 id="2-3-标记压缩法-Mark-Compact"><a href="#2-3-标记压缩法-Mark-Compact" class="headerlink" title="2.3 标记压缩法 Mark-Compact"></a>2.3 标记压缩法 Mark-Compact</h4><p>在整理压缩阶段，不再对标记的对象作回收，而是通过所有存活对象都像一端移动，然后直接清除边界以外的内存。</p>
<img src="/blog/blog/posts/blog/posts/5c68b0b8/image-20200922091120493.png" class>

<p>可以看到，标记的存活对象将会被整理，按照内存地址依次排列，而未被标记的内存会被清理掉，如此一来，当我们需要给新对象分配内存时，JVM 只需要持有一个内存的起始地址即可，这比维护一个空闲列表显然少了许多开销。</p>
<p>标记、整理算法不仅可以弥补标记、清除算法当中内存区域分散的缺点，也消除了复制算法当中，内存减半的高额代价。</p>
<h3 id="3-小结"><a href="#3-小结" class="headerlink" title="3. 小结"></a>3. 小结</h3><p>内存效率：复制算法 &gt; 标记清除算法 &gt; 标记整理算法 （时间复杂度） </p>
<p>内存整齐度：复制算法 &#x3D; 标记整理算法 &gt; 标记清除算法</p>
<p>内存利用率：标记整理算法 &#x3D; 标记清除算法 &gt; 复制算法</p>
<p>可以看出，效率上来说，复制算法是当之无愧的老大，但是却浪费了太多内存，而为了尽量兼顾上面所提到的三个指标，标记整理算法相对来说更平滑一些，但是效率上依然不尽如人意，它比复制算法多了一个标记的阶段，又比标记清除多了一个整理内存的过程。</p>
<p>所以 GC 算法其实是<strong>分代收集算法</strong></p>
<p><strong>年轻代：（Young Gen）</strong> </p>
<p>年轻代特点是区域相对老年代较小，对象存活低。</p>
<p>这种情况复制算法的回收整理，速度是最快的。复制算法的效率只和当前存活对象大小有关，因而很适用于年轻代的回收。而复制算法内存利用率不高的问题，通过 hotspot 中的两个 survivor 的设计得到缓解。</p>
<p><strong>老年代：（Tenure Gen）</strong></p>
<p>老年代的特点是区域较大，对象存活率高。</p>
<p>这种情况，存在大量存活率高的对象，复制算法明显变得不合适。一般是由标记清除或者是标记清除与标记整理的混合实现。</p>
<p>Mark 阶段的开销与存活对象的数量成正比，这点来说，对于老年代，标记清除或者标记整理有一些不符，但可以通过多核多线程利用，对并发，并行的形式提标记效率。</p>
<p>Sweep 阶段的开销与所管理里区域的大小相关，但 Sweep “就地处决”的 特点，回收的过程没有对象的移动。使其相对 其他有对象移动步骤的回收算法，仍然是是效率最好的，但是需要解决内存碎片的问题。</p>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Horsen Liu
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://horsenliu.gitee.io/blog/posts/5c68b0b8.html" title="06_GC 详解">http://horsenliu.gitee.io/blog/posts/5c68b0b8.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/blog/tags/JVM/" rel="tag"><i class="fa fa-tag"></i> JVM</a>
              <a href="/blog/tags/GC/" rel="tag"><i class="fa fa-tag"></i> GC</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/posts/d9304f42.html" rel="prev" title="05_堆 Heap">
      <i class="fa fa-chevron-left"></i> 05_堆 Heap
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/posts/d366874c.html" rel="next" title="集合">
      集合 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#0-%E5%B8%B8%E8%A7%81%E9%9D%A2%E8%AF%95%E9%A2%98"><span class="nav-text">0. 常见面试题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-GC-%E7%AE%97%E6%B3%95%E6%80%BB%E4%BD%93%E6%A6%82%E8%BF%B0"><span class="nav-text">1. GC 算法总体概述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-GC-%E5%9B%9B%E5%A4%A7%E7%AE%97%E6%B3%95"><span class="nav-text">2. GC 四大算法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-%E5%BC%95%E7%94%A8%E8%AE%A1%E6%95%B0%E6%B3%95"><span class="nav-text">2.1 引用计数法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-%E5%A4%8D%E5%88%B6%E7%AE%97%E6%B3%95-Copying"><span class="nav-text">2.2 复制算法 Copying</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-%E6%A0%87%E8%AE%B0%E6%B8%85%E9%99%A4%E6%B3%95-Mark-Sweep"><span class="nav-text">2.3 标记清除法 Mark-Sweep</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-%E6%A0%87%E8%AE%B0%E5%8E%8B%E7%BC%A9%E6%B3%95-Mark-Compact"><span class="nav-text">2.3 标记压缩法 Mark-Compact</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%B0%8F%E7%BB%93"><span class="nav-text">3. 小结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Horsen Liu"
      src="/blog/images/avatar.png">
  <p class="site-author-name" itemprop="name">Horsen Liu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">220</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">123</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/horsenliu" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;horsenliu" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://wpa.qq.com/msgrd?v=3&uin=1468224254&site=qq&menu=yes" title="QQ → https:&#x2F;&#x2F;wpa.qq.com&#x2F;msgrd?v&#x3D;3&amp;uin&#x3D;1468224254&amp;site&#x3D;qq&amp;menu&#x3D;yes" rel="noopener" target="_blank"><i class="fab fa-qq fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://sm.ms/image/jyArGeatQ9Plw4n" title="WeChat → https:&#x2F;&#x2F;sm.ms&#x2F;image&#x2F;jyArGeatQ9Plw4n" rel="noopener" target="_blank"><i class="fab fa-weixin fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:horsenliu@qq.com" title="E-Mail → mailto:horsenliu@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i></a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/blog/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Horsen Liu</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">707k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">10:43</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div><script color="252,100,35" pointColor="252,100,35" opacity="1" zIndex="-1" count="150" src="https://cdn.jsdelivr.net/npm/canvas-nest.js@1/dist/canvas-nest.js"></script>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>

<script src="/blog/js/bookmark.js"></script>




  




  
<script src="/blog/js/local-search.js"></script>













  

  

<script src="/blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/blog/live2dw/assets/assets/hijiki.model.json"},"display":{"superSample":2,"width":180,"height":360,"position":"left","hOffset":40,"vOffset":-60},"mobile":{"show":false,"scale":0.1},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body>
</html>
